Skip to content

Fix doubled node_modules path in sourcemap sources for natively-resolved civet packages#1890

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-sourcemap-source-attr
Draft

Fix doubled node_modules path in sourcemap sources for natively-resolved civet packages#1890
Copilot wants to merge 2 commits intomainfrom
copilot/fix-sourcemap-source-attr

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 1, 2026

Civet files loaded from node_modules packages (where the bundler resolves the file natively, not through the plugin's resolveId hook) produced malformed sourcemap source paths like ../node_modules/pkg/lib/node_modules/pkg/lib/math.civet instead of ../node_modules/pkg/lib/math.civet.

Root cause

Two distinct load paths exist in the plugin:

  1. Plugin-resolved files (resolveId appends outExt, e.g. .jsx): these land in a plugin namespace and the bundler uses source paths as-is — path.relative(outDir, filename) is correct.
  2. Natively-resolved files (id has no outExt suffix, e.g. a node_modules package whose main is a .civet file): the bundler resolves sourcemap sources entries relative to the input file's directory. A path like ../node_modules/pkg/index.civet resolved from node_modules/pkg/ becomes node_modules/node_modules/pkg/index.civet.

Changes

  • source/unplugin/unplugin.civet — Discriminate on id.endsWith(outExt): for natively-resolved files use path.relative(path.dirname(filename), filename) (basename relative to input dir) so the bundler resolves it correctly; keep existing logic for plugin-resolved virtual files.
  • test/integration.civet — Add integration test that creates a minimal node_modules fixture, builds with esbuild, and asserts the sourcemap sources entry is ../node_modules/test-civet-pkg/index.civet.
  • integration/example/build-node-modules.civet / integration/example/source/uses-pkg.civet — Supporting fixtures for the new test.

Copilot AI changed the title [WIP] Fix sourcemap source attribute for civet file in node_modules package Fix doubled node_modules path in sourcemap sources for natively-resolved civet packages Apr 1, 2026
Copilot AI requested a review from STRd6 April 1, 2026 04:07
Copilot finished work on behalf of STRd6 April 1, 2026 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sourcemap has incorrect source attr for civet file in node_modules package

2 participants